package org.springblade.modules.platform.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springblade.modules.platform.service.IEngineerValueTableService;
import org.springblade.modules.platform.service.IMeasuringPointTableService;
import org.springblade.modules.platform.service.IPhysicalValueTableService;
import org.springblade.modules.platform.vo.DataDetailsVO;
import org.springblade.modules.platform.vo.DeviceDetailsDTO;
import org.springblade.modules.platform.vo.PhysicalValueTableListVO;
import org.springblade.modules.platform.vo.ProductionChartVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/service-huateng-sxdb/data")
@Api(value = "", tags = "数据详情")
@Slf4j
public class DataDetailsController {

    private final IMeasuringPointTableService iMeasuringPointTableService;//一侧量集合
    private final IEngineerValueTableService iEngineerValueTableService;//工程量
    private final IPhysicalValueTableService iPhysicalValueTableService;//物理量

    @GetMapping("/details")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "数据详情", notes = "数据详情")
    public R<DataDetailsVO> getQuery(@RequestParam(value = "deptId") Long deptId,
                                     @RequestParam(value = "measurChainDirection") Integer measurChainDirection,
                                     @RequestParam(value = "gatherTime") Long gatherTime) {

        DataDetailsVO dataDetailsVO = new DataDetailsVO();
        List<DataDetailsVO.MeasuringPointTableVO> measuringPointTableVOS = iMeasuringPointTableService.selectListByDeptId(deptId, gatherTime,measurChainDirection);
        dataDetailsVO.setMeasuringPointTableVOS(measuringPointTableVOS);
        DataDetailsVO.EngineerValueTableVO engineerValueTableVO = iEngineerValueTableService.selectListByDeptId(deptId, gatherTime,measurChainDirection);
        dataDetailsVO.setEngineerValueTableVO(engineerValueTableVO);
        DataDetailsVO.PhysicalValueTableVO physicalValueTableVO = iPhysicalValueTableService.selectOneByDeptId(deptId, gatherTime,measurChainDirection);
        dataDetailsVO.setPhysicalValueTableVO(physicalValueTableVO);
        return R.data(dataDetailsVO);
    }


    @GetMapping("/productionChart")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "生成图表", notes = "生产图表")
    public R<ProductionChartVO> getProductionChart(@RequestParam(value = "measurChainCode") Long measurChainCode,
                                                   @RequestParam(value = "measurChainDirection",required = false) Integer measurChainDirection,
                                         @RequestParam(value = "gatherTime") Long gatherTime) {
        return R.data(iEngineerValueTableService.getChart(measurChainCode,gatherTime,measurChainDirection));

    }

    @GetMapping("/chart")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "生成图表v2", notes = "生产图表")
    public R<ProductionChartVO> getChart(@RequestParam(value = "deptId") Long deptId,
                                         @RequestParam(value = "measurChainDirection") Integer measurChainDirection,
                                         @RequestParam(value = "startTime",required = false) Long startTime,
                                         @RequestParam(value = "endTime",required = false) Long endTime) {
        return R.data(iEngineerValueTableService.getProductionChart(deptId,measurChainDirection,startTime,endTime));

    }


    @GetMapping("/deviceChart")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "设备属性图表", notes = "设备属性图表")
    public R<DeviceDetailsDTO> getDeviceChart(@RequestParam(value = "deviceId") String deviceId,
                                              @RequestParam(value = "measurChainDirection",required = false) Integer measurChainDirection,
                                              @RequestParam(value = "startTime",required = false) Long startTime,
                                              @RequestParam(value = "endTime",required = false) Long endTime) {
        return R.data(iMeasuringPointTableService.getDeviceChart(deviceId,measurChainDirection,startTime,endTime));

    }

    @GetMapping("/physicalChart")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "物理量生成图表", notes = "物理量生成图表")
    public R<PhysicalValueTableListVO> physicalChart(@RequestParam(value = "deptId") Long deptId,
                                                     @RequestParam(value = "measurChainDirection") Integer measurChainDirection,
                                                     @RequestParam(value = "startTime",required = false) Long startTime,
                                                     @RequestParam(value = "endTime",required = false) Long endTime) {
        return R.data(iPhysicalValueTableService.getProductionChart(deptId,measurChainDirection,startTime,endTime));

    }
}
